import { FormItemScheme, FormScheme } from '@/pages/form-model/interface';
import { ArrayProperty } from '@/pages/form-model/model/array.property';
import { BooleanProperty } from '@/pages/form-model/model/boolean.property';
import { FormProperty } from '@/pages/form-model/model/formProperty';
import { NumberProperty } from '@/pages/form-model/model/number.property';
import { ObjectProperty } from '@/pages/form-model/model/object.property';
import { StringProperty } from '@/pages/form-model/model/string.property';
import { FormModel } from './form.model';

export class FormFactory {
  static createForm(config: FormScheme) {
    return new FormModel(config);
  }

  static createProperty(
    props: FormItemScheme,
    namePath: string[],
    root?: FormModel,
  ) {
    const { type = 'string' } = props;
    let property: FormProperty;
    if (type === 'object') {
      property = new ObjectProperty(props, namePath, root);
    } else if (type === 'string') {
      property = new StringProperty(props, namePath, root);
    } else if (type === 'boolean') {
      property = new BooleanProperty(props, namePath, root);
    } else if (type === 'number') {
      property = new NumberProperty(props, namePath, root);
    } else if (type === 'array') {
      property = new ArrayProperty(props, namePath, root);
    }
    return property;
  }
}
